<?php include("../../core/connect.php");?>
<?php 
	$id_row=$_GET['id_row'];
	$add=$_GET['add'];
	$gia_tri_moi=$_GET['gia_tri_moi'];
	$hct_id=$_GET['hct_id'];
	$tien_chua_tt=$_GET['tien_chua_tt'];
	$count_del_hdct=$_GET['count_del_hdct'];
	$table=$_GET['table'];
	$id_table=$_GET['id_table'];
	$Cls_Id=$_GET['Cls_Id'];
	$Sph_Id=$_GET['Sph_Id'];
	$Dvt_Id=$_GET['Dvt_Id'];
	$giaban=$_GET['giaban'];
	$giaban_=$_GET['giaban_'];
	$giaban_=$_GET['giaban_'];
	$soluong=$_GET['soluong'];
	$tong_tien_hdct=$_GET['tong_tien_hdct'];
	$vat=$_GET['vat'];
	$tien_vat=$_GET['tien_vat'];
	$thanhtien=$_GET['thanhtien'];
	$tonggiatri=$gia_tri_moi+$thanhtien;
	if($add!=0){$stt=$id_row;}else{$stt=$count_del_hdct;}
?>
<?php 
	if($hct_id!=0)
	{
		if($table=='don_hang')
		{
			$update=mysql_query("update donhang_ct set 
							lsp = '$Cls_Id',
							sp = '$Sph_Id',	
							dv ='$Dvt_Id',
							dongia = '$giaban_',
							soluong = '$soluong',
							cong = '$tong_tien_hdct',
							vat = '$vat',
							tienvat = '$tien_vat',
							thanhtien = '$thanhtien'
							where id='$hct_id'
						");
		}
		//mysql_query("update donhang set giatri='$gia_tri_moi' where id='$id_table'");
		if($table=='hop_dong')
		{
			$update=mysql_query("update hopdong_ct set 
							loai_sp = '$Cls_Id',
							sanpham = '$Sph_Id',	
							donvi ='$Dvt_Id',
							dongia = '$giaban_',
							soluong = '$soluong',
							cong = '$tong_tien_hdct',
							vat = '$vat',
							tienvat = '$tien_vat',
							thanhtien = '$thanhtien'
							where id='$hct_id'
						");
			mysql_query("update contract set giatri_hd='$gia_tri_moi' where id='$id_table'");
		}
	}
	if($add==0)
	{
		if($table=='don_hang')
		{
			mysql_query("insert into donhang_ct
					(donhang_id,id_row,lsp,sp,dv,dongia,soluong,cong,vat,tienvat,thanhtien)
					value('$id_table','$count_del_hdct','$Cls_Id','$Sph_Id','$Dvt_Id','$giaban_','$soluong','$tong_tien_hdct','$vat','$tien_vat','$thanhtien')		
			");
		//mysql_query("update donhang set giatri='$tonggiatri' where id='$id_table'");
		}
		if($table=='hop_dong')
		{
			mysql_query("insert into hopdong_ct
					(hd_id,id_row,loai_sp,sanpham,donvi,dongia,soluong,cong,vat,tienvat,thanhtien)
					value('$id_table','$count_del_hdct','$Cls_Id','$Sph_Id','$Dvt_Id','$giaban_','$soluong','$tong_tien_hdct','$vat','$tien_vat','$thanhtien')		
			");
		}
	}
	
?>
<?php 
	
	$sql_Lsp=mysql_query("select services_type_id,services_type_name from tb_services_type where services_type_id='$Cls_Id'");
	$rs=mysql_fetch_array($sql_Lsp);
	$lsp=$rs['services_type_name'];
	
	$sql_sp=mysql_query("select IDproduct,Namepro from tb_product where IDproduct='$Sph_Id'");
	$rs_sp=mysql_fetch_array($sql_sp);
	$sp=$rs_sp['Namepro'];
	
	$sql_dv=mysql_query("select services_type_id,services_type_name from tb_services_type where services_type_id='$Dvt_Id'");
	$rs_dv=mysql_fetch_array($sql_dv);
	$dv=$rs_dv['services_type_name'];
$kq='
<div id="row_sua_'.$count_del_hdct.'">
	<div id="row_'.$count_del_hdct.'" style="overflow: hidden;display:block" class="row01">
		<div style="width:2.7%;text-align:center;" class="firstCol">
			'.$stt.'
		</div>
		<div style="width:12%;" class="Cols">
			'.$lsp.'
		</div>
		<div style="width:12%;" class="Cols">
			'.$sp.'
		</div>
		<div style="width:8%;" class="Cols">
			'.$dv.'
		</div>
		<div style="width:10%;text-align:right;" class="Cols">
			'.$giaban.'	
		</div>
		<div style="width:7%;text-align:center;" class="Cols">
			'.$soluong.'	
		</div>
		<div style="width:10%;text-align:right;" class="Cols">
			'.$tong_tien_hdct.'
		</div>
		<div style="width:10%;" class="Cols">
			'.$vat.'
		</div>
		<div style="width:11%;text-align:right;" class="Cols">
			'.$thanhtien.'
		</div>
		
		<div style="float:right;padding-right: 10px;" class="Cols">
			<b><span onclick="change_display(\'sua_hdct_'.$count_del_hdct.'\');change_display(\'row_'.$count_del_hdct.'\');document.getElementById(\'lsp_id_'.$count_del_hdct.'\').focus();" style="color:#FF9028;cursor: pointer;">Sửa</span>&nbsp;<span onclick="delete_hdct(1,\'\',\'8000000\',\'8000000\',\'0\');" style="color:#FF0000;cursor: pointer;">Xóa</span></b>
</div>
	<div>
			<input type="hidden" name="id_row" value="'.$count_del_hdct.'">
			<input type="hidden" name="id_record[]" value="'.$count_del_hdct.'">
			<input type="hidden" value="'.$Cls_Id.'" name="clsidarr[]">
			<input type="hidden" value="'.$Sph_Id.'" name="sphidarr[]">
			<input type="hidden" value="'.$Dvt_Id.'" name="donvitinharr[]">
			<input type="hidden" value="'.$giaban_.'" name="giabanarr[]">
			<input type="hidden" value="'.$soluong.'" name="soluongarr[]">
			<input type="hidden" value="'.$tong_tien_hdct.'" name="tongtienarr[]">
			<input type="hidden" value="'.$tien_vat.'" name="tienvatarr[]">
			<input type="hidden" value="'.$vat.'" name="vatarr[]">
			<input type="hidden" value="'.$thanhtien.'" name="thanhtienarr[]">
		</div> 
	</div>
	<div style="overflow: hidden;height:30px;display:none;" id="sua_hdct_'.$count_del_hdct.'" class="row01">
		<div style="width:2.7%;text-align:center;" class="firstCol">'.$count_del_hdct.'</div>
		<div style="width:12%;" class="Cols">
			<select style="width:100%;" onchange="show_spham(this.value,1);" name="Cls_Id_1" id="lsp_id_1">
				<option value="">Lựa chọn</option>
								<option selected="selected" value="1">TKW</option>
								<option value="2">Domain</option>
											
			</select>
		</div>
		<div id="arr_sp_'.$count_del_hdct.'" style="width:12%;" class="Cols">
			<select onchange="check_gia_vat(this.value,document.getElementById(\'soluong_1\').value,1);" style="width:100%;" id="Sph_Id_1" name="Sph_Id_1">
				<option value="">Lựa chọn</option>
								<option selected="selected" value="2">Thiết kế web công ty</option>
							</select>
		</div>
		<div style="width:8%;" class="Cols">
			<select style="width:100%;" name="Dvt_Id_1" id="dvt_id_1">
				<option value="">Lựa chọn</option>
								<option selected="selected" value="10">Bộ</option>
								<option value="1">Cái</option>
								<option value="11">Chiếc</option>
								<option value="13">dvt</option>
								<option value="20">Gói</option>
								<option value="14">kg</option>
								<option value="21">Người dùng</option>
								<option value="16">Thùng</option>
							</select>
		</div>
		<div style="width:10%;" class="Cols">
			<input type="text" readonly="" onblur="formatNumber(this.form.giaban_1);tien_hdct(1);" id="giaban_1" onclick="toUnformattedNumber(\'giaban_1\');" name="giaban_1" value="8.000.000" onkeypress="return isNumberKey(event);" style="width:95%;">
			<input type="hidden" id="giaban_1_" value="8000000" name="giaban_1_">
			<input type="hidden" id="gia_codinh_1" value="1" name="gia_codinh_1">
		</div>
		<div style="width:7%;" class="Cols">
			<input type="text" onkeyup="tien_hdct(1);" size="30" value="1" id="soluong_1" name="soluong_1" style="width:95%;" onkeypress="return isNumberKey(event);">
		</div>
		<div style="width:10%;" class="Cols">
			<input type="text" value="8.000.000" id="tong_cdd_1" style="width:95%;" disabled="true">
			<input type="hidden" value="8000000" name="tong_tien_hdct_1" id="tien_tong_1">
		</div>
		<div style="width:10%;" class="Cols">
			<input type="hidden" value="0" id="vat_dd_1" style="width:95%;" disabled="true">
			<input type="hidden" value="0" id="tien_vat_1" name="tien_vat_1">
			<input type="text" value="0" id="vat_1" name="vat_1" onkeyup="tien_hdct(1);" onkeypress="return isNumberKey(event);" style="width:95%;">
		</div>
		<div style="width:11%;" class="Cols">
			<input type="text" value="8.000.000" id="thanhtien_dd_1" style="width:95%;" disabled="true">
			<input type="hidden" value="8000000" id="thanhthien_1" name="thanhthien_1">
		</div>
		<div style="float:right;padding-right: 10px;" class="Cols">
			<span style="color:#FF9028;cursor: pointer;" onclick="check_add_hdct(1,1,\'8000000\',\'\',\'8000000\',\'0\');"><b>Lưu</b></span>&nbsp;<span onclick="change_display(\'sua_hdct_'.$count_del_hdct.'\');change_display(\'row_'.$count_del_hdct.'\');" style="color:#FF0000;cursor: pointer;"><b>Hủy</b></span>
		</div>
	</div>
</div>
';
echo json_encode($kq);
?>
	